using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Job1ActivityItem : MonoBehaviour
{
    public Transform FeedGroup, PayGroup;
    List<GameObject> freegameObjects = new List<GameObject>();
    List<GameObject> paygameObjects = new List<GameObject>();

    internal void Refresh(DayData dayData)
    {
        HideAll();
        for (int i = 0; i < dayData.freeList.Count; i++)
        {
            var obj = GetgameObjcet(i, FeedGroup, freegameObjects);

            obj.GetComponentInChildren<Text>().text = dayData.freeList[i].name;

            if (dayData.freestate == 1)
            {
                obj.transform.GetChild(1).gameObject.SetActive(true);
            }
            else
            {
                obj.transform.GetChild(1).gameObject.SetActive(false);
            }
        }
        for (int i = 0; i < dayData.payList.Count; i++)
        {
            var obj = GetgameObjcet(i, PayGroup, paygameObjects);
            obj.GetComponentInChildren<Text>().text = dayData.payList[i].name;

            if (dayData.paystate == 1)
            {
                obj.transform.GetChild(1).gameObject.SetActive(true);
            }
            else
            {
                obj.transform.GetChild(1).gameObject.SetActive(false);
            }
        }
    }

    private GameObject GetgameObjcet(int i, Transform Group, List<GameObject> gameObjects)
    {
        if (gameObjects.Count <= i)
        {
            gameObjects.Add(Instantiate(Resources.Load<GameObject>("Job1/Image"), Group));
        }
        gameObjects[i].gameObject.SetActive(true);

        return gameObjects[i];
    }
    private void HideAll()
    {
        HideItem(freegameObjects);

        HideItem(paygameObjects);
    }

    private void HideItem(List<GameObject> Objects)
    {
        for (int i = 0; i < Objects.Count; i++)
        {
            Objects[i].gameObject.SetActive(false);
        }
    }
}
